/**
 * 
 */
package simulation;

import java.awt.geom.Line2D;
import java.awt.geom.Rectangle2D;

/**
 * @author aclayton
 *
 */
public class LineSeg{
	private Point start, end;
	
	public LineSeg(Point start, Point end){
		this.start = start;
		this.end = end;
	}
	
	public double getLength(){
		return start.getDistance(end);
	}
	
	public Point getVector(){
		return end.subtract(start);
	}
	
	public Rect getBoundingBox(){
		Line2D tempLine = new Line2D.Double(start.getX(), start.getY(), end.getX(), end.getY());
		
		Rectangle2D r = tempLine.getBounds2D();
		return new Rect(r.getX(),r.getMaxX(), r.getMaxY(), r.getMinY());//.getWidth() + r.getX(),r.getY(),r.getY()-r.getHeight());
	}
	
	public Point getPerpendicularVector(){
		return getVector().getPerpendicularVector();
	}
	
	public boolean intersectBox(Rect rect){
		if(rect.pointInBox(start) || rect.pointInBox(end))
			return true;
		
		LineSeg[] sides = rect.getSides();
		
		for(LineSeg s : sides){
			if(interectsSeg(s))
				return true;
		}
		
		
		
		return false;
	}
	
	public boolean interectsSeg(LineSeg otherseg){
		Line2D tempLine = new Line2D.Double(start.getX(), start.getY(), end.getX(), end.getY());
		Line2D tempLine2 = new Line2D.Double(otherseg.start.getX(), otherseg.start.getY(), otherseg.end.getX(), otherseg.end.getY());
		
		return tempLine.intersectsLine(tempLine2);
		
	}
	public boolean intersectsCircle(Circle circle){
		return circle.intersectsLineSeg(this);
	}

	/**
	 * @return the start
	 */
	public Point getStart() {
		return start;
	}

	/**
	 * @return the end
	 */
	public Point getEnd() {
		return end;
	}
	

}
